import {Injectable,OnInit} from '@angular/core';

import {Http, Response,Headers, RequestOptions} from '@angular/http';
import { Observable } from 'rxjs/Rx';

import {User,Picture} from './user';
import {SignComponent} from './sign.component';


@Injectable()
export class UserService {

 loading:boolean;
 data:any;
constructor(private http: Http) {}

  //通过get获取y用户信息
  userGet(user:User){
    this.loading = true;
    console.log(user);
    this.http.get('http://192.168.1.110:8080/messagebus/v1/uzer/54obz163a7am/isExistUzerByMobile?mobile=12345678912').subscribe((res:Response) =>{
      this.data = res.json();
      //this.data = user.mobile;

      this.loading= false;
    });
  }
  //本地测试
  userGetA(user:User){
    this.loading = true;
    this.http.get('../assets/data/user.json').subscribe((res:Response) =>{
      this.data = res.json();
      this.loading= false;
    });
  }
  //通过get获取图片信息 发送请求
  imgGet(picture:Picture){
    this.loading = true;
    this.http.get('../assets/data/picture.json').subscribe((res:Response) =>{
      this.data = res.json();
      this.loading = false;
    })
  }

  //通过post验证图片验证码对错
  imgPost(){
    this.loading = true;
    this.http.post('http://jsonplaceholder.typicode.com/posts',
    JSON.stringify({
      body:'bar',
      title:'foo'
    })
  ).subscribe((res:Response) =>{
      this.data = res.json();
      this.loading= false;
    });
  }
}
